package main.dao;

import main.common.product.Fruit;
import main.common.strategy.DiscountStrategy;

import java.util.HashMap;
import java.util.Map;

public class Order {

    private final Map<Fruit, Integer> fruitMap = new HashMap<>();


    public double calculateTotal(DiscountStrategy discountStrategy) {
        double total = 0;
        for(Map.Entry<Fruit, Integer> entry : fruitMap.entrySet()) {
            Fruit fruit = entry.getKey();
            total += fruit.calculatePrice(entry.getValue());
        }


        return discountStrategy.applyDiscount(total);
    }

    public void addFruit(Fruit fruit, int weight) {
        fruitMap.put(fruit, weight);
    }

    public void removeFruit(Fruit fruit) {
        fruitMap.remove(fruit);
    }

}
